package com.example.blog.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.blog.base.PageResult;
import com.example.blog.base.Result;
import com.example.blog.entity.Reply;
import com.example.blog.entity.dto.reply.AddReplyDTO;
import com.example.blog.entity.dto.reply.PageQueryDTO;
import com.example.blog.entity.vo.comment.ReplyDetailIfoVO;
import com.example.blog.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 二级评论模块
 * <p>
 * 二级评论表 前端控制器
 * </p>
 *
 * @author wlh
 * @since 2024-01-10
 */
@RestController
@RequestMapping("/blog/reply")
public class ReplyController {


    @Autowired
    private ReplyService replyService;


    /**
     * 新增二级评论
     * @param addReplyDTO
     * @return
     */
    @PostMapping("/add")
    public Result<Long> add(@RequestBody AddReplyDTO addReplyDTO) {
        Long id = replyService.add(addReplyDTO);
        return Result.successData(id);
    }

    /**
     * 删除二级评论
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public Result<Void> del(@PathVariable Long id) {
        replyService.removeById(id);

        return Result.success();
    }

    /**
     * 分页获取二级评论
     * @param pageQueryDTO
     * @return
     */
    @PostMapping("/page-list")
    public PageResult<ReplyDetailIfoVO> pageList(@RequestBody @Validated PageQueryDTO pageQueryDTO) {
        Page<ReplyDetailIfoVO> pagedList = replyService.pageList(pageQueryDTO);

        return PageResult.format(pagedList);
    }
}
